package com.sinbader.xiaole.common.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import com.sinbader.xiaole.common.entity.TencentSmsRecord;
import com.sinbader.xiaole.common.mapper.TencentSmsRecordMapper;
import com.sinbader.xiaole.common.model.params.TencentSmsRecordParam;
import com.sinbader.xiaole.common.model.result.TencentSmsRecordResult;
import  com.sinbader.xiaole.common.service.TencentSmsRecordService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 腾讯短信记录 服务实现类
 * </p>
 *
 * @author LuoYong
 * @since 2020-04-22
 */
@Service
public class TencentSmsRecordServiceImpl extends ServiceImpl<TencentSmsRecordMapper, TencentSmsRecord> implements TencentSmsRecordService {

    @Override
    public void add(TencentSmsRecordParam param){
        TencentSmsRecord entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TencentSmsRecordParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TencentSmsRecordParam param){
        TencentSmsRecord oldEntity = getOldEntity(param);
        TencentSmsRecord newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TencentSmsRecordResult findBySpec(TencentSmsRecordParam param){
        return null;
    }

    @Override
    public List<TencentSmsRecordResult> findListBySpec(TencentSmsRecordParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TencentSmsRecordParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TencentSmsRecordParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TencentSmsRecord getOldEntity(TencentSmsRecordParam param) {
        return this.getById(getKey(param));
    }

    private TencentSmsRecord getEntity(TencentSmsRecordParam param) {
        TencentSmsRecord entity = new TencentSmsRecord();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
